class ChangeDir extends JSCommand {
	
	private static final String cmdName = "cd";
	private static final String NO_DIR = "%s: No such file or directory";
	
	public String runCommand(String[] commandArgs, JShell shell) {
	
		String result = new String();
		JSDirectory workDir = shell.getWorkDir();
		String address = commandArgs[1];
		String[] parsedAddress = Directory.parseAddress(address);
		
		boolean dirNotFound = false;
		String dirName;
		int i = 0;
		while (i < parsedAddress.length &&
				!dirNotFound) {
			
			dirName = parsedAddress[i];
			JSDirectory fetchedDir = (JSDirectory) workDir.getFile(dirName);
			
			if (fetchedDir == null) {
				dirNotFound = true;
				result = String.format(NO_DIR, dirName);
			} else {
				shell.setWorkDir(fetchedDir);
			}
			
			i++;
					
		}
		
		return result;
	
	}
	
	private boolean isValidArgs(String[] cmdArgs, JSDirectory workDir) {
		return true;
	}
}
